package com.dragon.app.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.channels.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;

/**
 * @Author: longtao
 * @Date: 2019/5/28
 * @Version: 1.0
 * @Description:
 */
public class Test2 {

    public static void main(String[] args) throws IOException {


        SocketChannel schannel = SocketChannel.open(new InetSocketAddress("127.0.0.1", 9090));
        schannel.configureBlocking(false);

        ByteBuffer buffer = ByteBuffer.allocate(1024);

        Scanner scanner = new Scanner(System.in);


        while (scanner.hasNext()){
            System.out.println("scanner in");
            String string = scanner.next();
            buffer.put(string.getBytes());
            buffer.flip();
            schannel.write(buffer);
            buffer.clear();
        }

        schannel.close();


    }


}
